﻿namespace TemplateTools {
    public class TemplateField {
        public TemplateFieldDefinition FieldDefinition { get; private set; }
        public int StartLocation { get; private set; }
        public int Length { get; private set; }

        public static TemplateField Parse(int startLocation, int length, string fieldDef) {
            TemplateField field = new TemplateField {
                FieldDefinition = TemplateFieldDefinition.Parse(fieldDef),
                StartLocation = startLocation,
                Length = length
            };
            return field;
        }

        public string Render(string template, string value) {
            string before = template.Substring(0, StartLocation);
            string after = template.Substring(StartLocation + Length + 1);
            return before + value + after;
        }
    }
}
